﻿
@{
    ViewBag.Title = "DicOrderRejectEdit";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@model CGT.Infrastructure.Dto.NetworkOrderRejectDicInterfaceDto
@section style{
    <style>
        .form-horizontal .control-label {
            width: 20%;
            float: left;
            text-align: right;
        }

        .col-sm-3 {
            width: 80%;
            float: left;
        }
         .col-sm-3 select{
            float: left;
        }
    </style>
}
<form id="form1" class="form-horizontal">
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="box-body">
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="name">分类名称：</label>
                        <div class="col-sm-3">
                            <select class="form-control" style="width:150px;" name="selMasterBizType" id="selMasterBizType"></select>
                            <select class="form-control" style="width:150px; margin-left:5px;" name="selBizType" id="selBizType"></select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="name">驳回信息：</label>
                        <div class="col-sm-3">
                            <textarea class="form-control" rows="3" style="width:305px;" name="txtRejectContent" id="txtRejectContent">@Model.RejectContent</textarea>
                        </div>
                    </div>
                </div>
                <div class="box-footer text-center">
                    <button class="btn btn-primary" type="button" id="btnSave">确 定 </button>
                    <button class="btn" type="button" id="cancel">取 消 </button>
                    <input type="hidden" id="DicId" name="DicId" value="@Model.DicId" />
                </div>
            </div>

        </div>
        <!-- /.row -->
    </section>

</form>
@section scriptsBottom{
    <script type="text/javascript">
       $(document).ready(function () {
           initFormValidate();
           //分类
           initMasterBizType();
           initBindBizType();
           $("#btnSave").click(function(){
               save();
           });
           $("#cancel").click(function () {
               BMCW.closeTopLayer();
           });
       });
       function initFormValidate() {
           $("#form1").bootstrapValidator({
               submitHandler: function (valiadtor, loginForm, submitButton) {
                   valiadtor.defaultSubmit();
               },
               fields: {
                   selBizType: {
                       validators: {
                           notEmpty: {
                               message: '请选择分类'
                           }
                       }
                   },
                   txtRejectContent: {
                       validators: {
                           notEmpty: {
                               message: '驳回信息不能为空'
                           },
                           stringLength: {
                               /*长度提示*/
                               min: 1,
                               max: 500,
                               message: '长度必须在1到500之间'
                           }
                       }
                   }
               }
           });
       }

       function save()
       {
           var bootstrapValidator = $("#form1").data('bootstrapValidator');
           bootstrapValidator.validate();

           if (bootstrapValidator.isValid()) {
               var arrData = $("#form1").serializeArray();
               var data = {};
               for (var i = 0; i < arrData.length; i++) {
                   data[arrData[i].name] = arrData[i].value;
               }
               var url = '@Url.Action("SaveRejectDic", "Order")'
               BMCW.ajax({
                   url: url,
                   type: "POST",
                   data: data,
                   success: function (o) {
                       if (o.status == 0) {
                           BMCW.msg("保存成功",function(){
                               BMCW.getTopSelectedWin().search();
                           });
                       } else {
                           BMCW.alert("保存失败");
                       }
                   }
               });
           }
       }

       //一级分类
        function initMasterBizType()
        {
            var mid = @Model.MasterBizTypeId;
            var url = '@Url.Action("GetMasterBizTypeList", "Order")';
            $("#selMasterBizType").append("<option value='0'>全部分类</option>");
            BMCW.ajax({
                url: url,
                type: "GET",
                success: function (o) {
                    if (o.status == 0) {
                        $.each(o.data, function (i) {
                            var sel = "";
                            if(o.data[i].MasterBizTypeID == mid)
                            {
                                sel = "selected='true'";
                            }
                            $("#selMasterBizType").append("<option value='" + o.data[i].MasterBizTypeID + "' "+ sel +">" + o.data[i].MasterBizTypeName + "</option>");
                        });
                    }
                }
            });
        }

        function initBindBizType()
        {
            var mid = @Model.MasterBizTypeId;
            var bid = @Model.BizTypeId;
         
            $("#selBizType").append("<option value=''>全部子类</option>");
            $("#selMasterBizType").bind("change", function () {
                var typeId = $(this).val();
                bindBizTypeSel(typeId,0);
            });
            if(mid>0)
            {
                bindBizTypeSel(mid,bid);
            }
        }

        function bindBizTypeSel(masterId,bid)
        {
            var url = '@Url.Action("GetBizTypeListByMasterId", "Order")';
            BMCW.ajax({
                url: url,
                data:{ "masterId": masterId },
                type:"GET",
                success: function (rd) {
                    if (rd.status == 0) {
                        $("#selBizType").empty();
                        $("#selBizType").append("<option value=''>全部子类</option>");
                        var dataObj = rd.data;
                        for (var i = 0; i < dataObj.length; i++) {
                            var sel = "";
                            var bizTypeId = dataObj[i].BizTypeID;
                            var bizTypeName = dataObj[i].BizTypeName;
                            if(bizTypeId == bid)
                            {
                                sel = "selected='true'";
                            }
                            $("#selBizType").append("<option value='" + bizTypeId + "' "+ sel +">" + bizTypeName + "</option>");
                        }
                    }
                }
            })
        }
    </script>
}

